<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2022-06-21
 * Time: 16:24:13
 * Info:
 */

namespace app\api\controller;

use app\Request;

class ApiController extends \app\BaseController
{

    protected $token = '';

    protected $domain = '';

    //用户id
    protected $userId = 0;

    protected $request;

    //应用实例
    protected $app;

    public function __construct()
    {
        $this->request = request();

        //配置统一入口，只让访问index方法
        $controllerName = explode('\\', request()->controller);
        if (request()->app != 'api' || end($controllerName) != 'IndexController' || request()->action != 'index') {
            if ( ! (request()->app == 'api' && end($controllerName) == 'CommonController')) {
                //这个if是为了兼容api/Common控制器可以直接访问，为了向下兼容
                return response('error');
            }

        }
    }

    //此方法用于设置参数
    public function setInit($user_id)
    {
        $this->userId = $user_id;

        return true;
    }

}
